

import axios from 'axios';
import {UserRegister,UserLogin,HeaderAuth, Score,scoreList} from './types';

const instance = axios.create({
    baseURL:'http://localhost:3000/api',
    timeout: 5000,
    headers: { 
        'X-Custom-Header': 'foobar',
        'Content-Type': 'application/json',
    }
});

// 用户注册
const userRegister = async (data:UserRegister)=>{
    return await instance({
        method:'POST',
        url:'/user/register',
        data:data
    });
}
// 用户登录
const userLogin = async (data:UserLogin)=>{
    return await instance({
        method:'POST',
        url:'/user/login',
        data:data
    });
}
// 获取用户信息
const userInfo = async (header:HeaderAuth)=>{
    return await instance({
        method:'GET',
        url:'/user/info',
        headers:{...header}
    });
}

// 增加用户积分
const userScore =async (data:Score)=>{
    return await instance({
        method:'POST',
        url:'/user/score',
        data:data,
    });
}

// 积分列表
const userScoreList =async (data:scoreList)=>{
    return await instance({
        method:'POST',
        url:'/user/list',
        data:data,
    });
}


export { userRegister, userLogin, userInfo,userScore,userScoreList };